<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<div id="comments">
    <?php $this->comments()->to($comments); ?>
    <?php if ($comments->have()): ?>
        <h3><?php $this->commentsNum('暂时还没有评论哟，快来抢沙发吧', '当前只有一条评论，快来发表你的意见吧', '当前共%d条评论'); ?></h3>

        <ul class="mdui-list">
            <?php $this->comments()->to($comments); ?>
            <?php while ($comments->next()): ?>
                <div>
                    <div>
                        <img class="mdui-card-header-avatar"
                             src="<?php $this->options->themeUrl('inc/img/Avatar.webp'); ?>"/>
                        <div>
                            <div class="mdui-card-header-title"><?php $comments->author(); ?>
                                &nbsp;&nbsp;&nbsp;<sup><?php echo $comments->sequence(); ?>楼</sup></div>
                            <div class="mdui-card-header-subtitle"><?php $comments->date('Y-m-d H:i'); ?></div>
                        </div>
<!--                        <button class="mdui-btn mdui-text-color-theme mdui-float-right" href="--><?php //$comments->responseUrl(); ?><!--">回复</button>-->
                    </div>
                    <div style="margin-left: 50px"><?php $comments->content(); ?></div>
                    <hr>
                </div>

            <?php endwhile; ?>

        </ul>


    <?php endif; ?>

    <?php if ($this->allow('comment')): ?>
        <div id="<?php $this->respondId(); ?>" class="respond">
            <div class="cancel-comment-reply">
                <?php $comments->cancelReply(); ?>
            </div>

            <h4 id="response"><?php _e('添加新评论'); ?></h4>
            <form method="post" action="<?php $this->commentUrl() ?>" id="comment-form" role="form">
                <?php if ($this->user->hasLogin()): ?>
                    <p><?php _e('登录身份: '); ?><a
                                href="<?php $this->options->profileUrl(); ?>"><?php $this->user->screenName(); ?></a>.
                        <a href="<?php $this->options->logoutUrl(); ?>" title="Logout"><?php _e('退出'); ?> &raquo;</a>
                    </p>
                <?php else: ?>

                    <p>
                    <div class="mdui-textfield">
                        <label for="author" class="required mdui-text-color-theme"><?php _e('*称呼：'); ?></label>
                        <input type="text" name="author" id="author" class="text mdui-textfield-input"
                               value="<?php $this->remember('author'); ?>" required type="text"
                               placeholder="User Name"/>
                    </div>
                    </p>


                    <p>
                    <div class="mdui-textfield">
                        <label for="author" class="required mdui-text-color-theme"><?php _e('*Email：'); ?></label>
                        <input class="text mdui-textfield-input"
                               value="<?php $this->remember('author'); ?>" required type="text"
                               placeholder="Email Address"
                               type="email" name="mail" id="mail"
                               value="<?php $this->remember('mail'); ?>"<?php if ($this->options->commentsRequireMail): ?> required<?php endif; ?> />
                    </div>
                    </p>


                    <p>
                    <div class="mdui-textfield">

                        <label for="url" class="required mdui-text-color-theme"><?php _e('网站：'); ?></label>
                        <input type="url" name="url" id="url" class="text mdui-textfield-input"
                               placeholder="<?php _e('http://'); ?>"
                               value="<?php $this->remember('url'); ?>"<?php if ($this->options->commentsRequireURL): ?> required<?php endif; ?> />
                    </div>
                    </p>


                <?php endif; ?>


                <p>
                    <label for="textarea" class="required mdui-text-color-theme"><?php _e('*评论内容：'); ?></label>
                <div class="mdui-textfield">
                    <textarea class="mdui-textfield-input" rows="4" rows="8" cols="50" name="text" id="textarea"
                              placeholder="Message"></textarea>
                </div>
                </p>


                <p>
                    <button type="button" onclick="postComment()" class="mdui-color-theme mdui-btn mdui-ripple"><?php _e('提交评论'); ?></button>
                </p>

            </form>
        </div>
    <?php else: ?>
        <h3><?php _e('评论已关闭'); ?></h3>
    <?php endif; ?>
    <script>
    	function postComment(){
    		var textarea = document.getElementById('textarea');
    		console.log(textarea.value);
    		if(textarea.value == ''){
	    		var load_progress = mdui.snackbar({
		            timeout: 100,
		            message: '请输入你的评价内容',
		            position: 'bottom'
		        });
    		}
    		
    		var form = document.getElementById('comment-form');
    		form.submit();
    		
    			var load_progress = mdui.snackbar({
		            timeout: 100,
		            message: '评论成功',
		            position: 'bottom'
		        });
    	}
    </script>
</div>
